/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SessionBeans.actions;

import SessionBeans.entites.FileService;
import api.action.crates.Server.DeleteFileCrate;
import api.exception.TCloudAplicationException;
import entities.AccountHeader;
import entities.File;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

/**
 *
 * @author Tomas
 */
@Stateless
@LocalBean
public class DeleteFileService implements InvokeActionInterface<DeleteFileCrate>{
    @EJB
    private FileService fileService;

    @Override
    public void processAction(DeleteFileCrate actionData, Long userId, AccountHeader accHeader) throws TCloudAplicationException {
        File findedFile = Utils.findFile(accHeader.getRootFolder(), actionData.getPath());
        if(findedFile == null){
            throw new TCloudAplicationException(103, actionData.getPath());
        }
        
        fileService.deleteFile(userId, findedFile.getId());
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
}
